<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- import Vue before Element -->
    <script src="data/unpkg.com_vue@2.7.14_dist_vue.js"></script>
    <!-- import JavaScript -->
    <script src="data/unpkg.com_element-ui@2.15.13_lib_index.js"></script>
    <script src="data/axios-0.18.0.js"></script>
    <link rel="stylesheet" href="data/unpkg.com_element-ui@2.15.13_lib_theme-chalk_index.css">
</head>

<body>
<div id="app">
    <h1>用户列表</h1>
    <div style="float: left;line-height: 40px;">账号/手机号:</div>
    <el-input
            placeholder="请输入"
            v-model="input"
            clearable style="width: 212px;float: left;margin-left: 15px;">
    </el-input>
    <div style="float: left;line-height: 40px;margin-left: 120px;margin-right: 16px;">状态:</div>
    <template>
        <el-select v-model="value" placeholder="请选择" style="float: left;">
            <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
        </el-select>

    </template>
    <el-row style="float: left;margin-left: 70px;">
        <el-button type="primary" @click="init">查询</el-button>
    </el-row>

    <div style="margin-top: 80px">
        <el-row>
            <el-button size="medium">批量操作</el-button>
        </el-row>
    </div>

    <template>
        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    prop="name"
                    label="账号"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="nickname"
                    label="用户昵称"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="email"
                    label="邮箱"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="手机"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="lastTime"
                    label="最后活动时间"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="certificationStatus"
                    label="实名认证"
                    width="180">
                <template slot-scope="scope">
                    <span>{{ scope.row.certificationStatus != '通过' ? '否' : '是' }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="账号状态"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="operation"
                    label="操作"
                    width="180">
                <template slot-scope="scope">
                    <el-button type="text" @click="open(scope.row.id,scope.row.status)">
                        <template>
                            <span>{{ scope.row.status == '冻结' ? '解冻' : '冻结' }}</span>
                        </template>
                    </el-button>
                    <el-button type="text" @click="look(scope.row,dialogFormVisible = true)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
    </template>

    <el-dialog title="详细信息" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="用户名:" :label-width="formLabelWidth">
                <span>{{form.name}}</span>
            </el-form-item>
            <el-form-item label="号码:" :label-width="formLabelWidth">
                <span>{{form.number}}</span>
            </el-form-item>
            <el-form-item label="性别:" :label-width="formLabelWidth">
                <span>{{form.sex}}</span>
            </el-form-item>
            <el-form-item label="生日:" :label-width="formLabelWidth">
                <span>{{form.birth}}</span>
            </el-form-item>
            <el-form-item label="地区:" :label-width="formLabelWidth">
                <span>{{form.region}}</span>
            </el-form-item>
            <el-form-item label="创建时间:" :label-width="formLabelWidth">
                <span>{{form.createTime}}</span>
            </el-form-item>
            <el-form-item label="信誉分:" :label-width="formLabelWidth">
                <span>{{form.creditScore}}</span>
            </el-form-item>
            <el-form-item label="邮箱:" :label-width="formLabelWidth">
                <span>{{form.email}}</span>
            </el-form-item>
            <el-form-item label="状态:" :label-width="formLabelWidth">
                <span>{{form.status}}</span>
            </el-form-item>
            <el-form-item label="用户介绍:" :label-width="formLabelWidth">
                <span>{{form.signature}}</span>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogFormVisible = false">关 闭
            </el-button>
        </div>

    </el-dialog>
    <!--分页插件-->
    <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total"
                background
                layout="prev, pager, next"
                :total="1000">
        </el-pagination>
    </div>


</div>


</body>
<script>

    var Main = {
        data() {
            return {
                input: '',
                options: [
                    {
                        value: '选项1',
                        label: '全部'
                    },
                    {
                        value: '选项2',
                        label: '正常'
                    },
                    {
                        value: '选项3',
                        label: '冻结'
                    }
                ],
                value: '',
                tableData: [],/*列表展示数据*/

                pagination: {
                    //分页相关模型数据
                    currentPage: 1,	//当前页码
                    pageSize: 8,	//每页显示的记录数
                    total: 0,		//总记录数
                },

                dialogFormVisible: false,
                form: {
                    id: '',
                    name: '',           //用户名
                    number: '',         //用户号码
                    sex: '',            //性别
                    birth: '',          //生日
                    region: '',         //地区
                    createTime: '',     //创建时间
                    creditScore: '',   //信誉分
                    email: '',          //邮箱
                    status: '',         //状态
                    signature: '',      //介绍

                },
                formLabelWidth: '120px',

            }

        },
        /*一打开页面就执行方法*/
        created() {
            this.init();
        },
        /*方法*/
        methods: {
            init() {
                var value = this.value === '选项2' ? '正常' : this.value === '选项3' ? '冻结' : '';
                axios({
                    method: 'get',
                    url: '/admin/userList.html/' + this.pagination.currentPage + '/' + this.pagination.pageSize,
                    params: {
                        number: this.input,
                        status: value,
                    }
                }).then(res => {
                    console.log(res.data.data)
                    this.pagination.total = res.data.data.total;
                    this.pagination.currentPage = res.data.data.current;
                    this.pagination.pagesize = res.data.data.size;
                    this.tableData = res.data.data.records;
                })
            },
            /*切换页码*/
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage
                this.init()
            },
            /*弹窗*/
            open(id, status) {
                /*定义弹框值*/
                var title = status === '冻结' ? '解冻确认' : '冻结确认';
                var tips = status === '冻结' ? '是否确认解冻该用户？' : '冻结用户无法登录进行操作，是否确认冻结该用户？';
                /*定义请求*/
                status = status === '冻结' ? 'thawUsers' : 'freezeUsers';

                const h = this.$createElement;
                this.$msgbox({
                    title: title,
                    message: h('p', null, [
                        h('span', null, tips),
                        // h('i', { style: 'color: teal' }, 'VNode')
                    ]),
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: (action, instance, done) => {
                        if (action === 'confirm') {
                            instance.confirmButtonLoading = true;
                            instance.confirmButtonText = '执行中...';
                            /*id*/
                            var ids = [id]
                            /*拼接请求*/
                            axios.put('/admin/' + status + '.html?ids=' + ids).then(res => {
                                this.init();
                                this.successMessage(res.data.data)
                            });
                            setTimeout(() => {
                                done();
                                setTimeout(() => {
                                    instance.confirmButtonLoading = false;
                                }, 0);
                            }, 0);
                        } else {
                            done();
                        }
                    }
                })
            },
            /*提示消息*/
            successMessage(data) {
                this.$message({
                    message: data,
                    type: 'success'
                });
            },
            /*查看个人信息*/
            look(user){
                this.form.name=user.name;
                this.form.number=user.number;
                this.form.birth=user.birth;
                this.form.sex=user.sex;
                this.form.region=user.region;
                this.form.createTime=user.createTime;
                this.form.creditScore=user.creditScore;
                this.form.email=user.email;
                this.form.status=user.status;
                this.form.signature=user.signature;
            },

        }

    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')

</script>
</html>